package yutProject;

import java.awt.*;
import java.awt.event.*;
import java.awt.Graphics;
import java.awt.Image;
import java.awt.Toolkit;

import javax.jws.soap.InitParam;
import javax.swing.*;

public class Painter extends JFrame implements ActionListener {
	JLayeredPane jp;
	JPanel back_Image, frontp;

	JButton play_Game_bt = new JButton("Play Game", new ImageIcon(
			"images/Start_icon.jpg"));
	JButton start_bt = new JButton("Start");
	JButton exit_bt = new JButton("End", new ImageIcon("images/Exit_icon.jpg"));
	JButton throw_bt = new JButton("Throw", new ImageIcon(
			"images/Throw_icon.jpg"));
	JButton horse_P1_bt = new JButton("P1", new ImageIcon("images/Horse1.jpg"));
	JButton horse_P2_bt = new JButton("P2", new ImageIcon("images/Horse2.jpg"));
	JButton horse_P1_1_bt = new JButton("P1-1", new ImageIcon(
			"images/Horse1.jpg"));
	JButton horse_P2_1_bt = new JButton("P2-1", new ImageIcon(
			"images/Horse2.jpg"));

	JButton horse_P1_twin = new JButton("P1Twin");
	JButton horse_P2_twin = new JButton("P2Twin");

	Button turn1_bt = new Button("Player1's turn ");
	Button turn2_bt = new Button("Player2's turn");
	JButton substitude_bt;

	Button win_P1 = new Button("Player 1 WIN!!!!!");
	Button win_P2 = new Button("Player 2 WIN!!!!!");

	Button Do = new Button("Do");
	Button Gae = new Button("Gae");
	Button Gul = new Button("Gul");
	Button Yut = new Button("Yut");
	Button Mo = new Button("Mo");
	Button Back_do = new Button("-Do");

	Image scene1, scene2;
	Image yut_img_front, yut_img_back, yut_img_bottom;
	Image yut_img_minus;

	Main main = new Main();

	public static int bt_value = 0;
	boolean throw_step = true;
	boolean keep_doing = false;
	public static int keep_Array[] = new int[10];

	public static int keep_init = 0;
	public static int array_count = 0;
	int part_Ofhorse = 0;
	int io = 0;
	int use1 = 0, use2 = 0, use3 = 0, use4 = 0;
	int sceneNum = 1;
	int startbutton_w = 100;
	int startbutton_h = 100;
	int titlebutton_w = 160;
	int titlebutton_h = 60;
	int throwbutton_w = 120;
	int throwbutton_h = 110;
	int throw_push = 1;
	int judge_Value[] = { 99, 99, 99, 99 };
	int maindevision = 1;
	int turn = 0;
	int throwcount = 0;
	int game_Start = 0;
	int player_x[] = { 0, 0, 0, 0, 0, 0 };
	int player_y[] = { 0, 0, 0, 0, 0, 0 };
	int catch_horse = 0;

	public static int work_together1 = 99;
	public static int work_together2 = 99;

	boolean go_backpoint1 = false;

	boolean go = false;
	boolean onemore = false;

	private final int CANVAS_SIZE_X = 800;
	private final int CANVAS_SIZE_Y = 600;

	private Frame frame;
	private Graphics canvas;

	Painter() {
		setLayout(null);
		jp = new JLayeredPane();

		back_Image = new JPanel() {
			public void paintComponent(Graphics g) {
				g.drawImage(scene1, -10, -10, 800, 600, this);

			}

		};
		jp.setLayout(null);

		jp.setBounds(0, 0, 800, 600);

		back_Image.setBounds(0, 0, 800, 600);
		play_Game_bt.setBounds(CANVAS_SIZE_X / 2 - 80, CANVAS_SIZE_Y / 2,
				titlebutton_w, titlebutton_h);
		exit_bt.setBounds(CANVAS_SIZE_X / 2 - 80, CANVAS_SIZE_Y / 2 + 100,
				titlebutton_w, titlebutton_h);

		jp.add(back_Image, new Integer(0));
		jp.add(play_Game_bt, new Integer(1));
		jp.add(exit_bt, new Integer(1));
		add(jp);

		addAction_button();
		set_Frame();
		load_Images();
		button_Add();

		setVisible(true);

	}

	public void actionPerformed(ActionEvent e) {
		String name = e.getActionCommand();

		if (name != null) {
			if ("Play Game".equals(name)) {
				play_Game_Button(name);
				back_Image = new JPanel() {
					public void paintComponent(Graphics g) {
						g.drawImage(scene2, -10, -15, CANVAS_SIZE_X,
								CANVAS_SIZE_Y, this);
						g.drawImage(yut_img_bottom, 0, 10, 219, 140, this);
						draw_YutImage(g, judge_Value[0], judge_Value[1],
								judge_Value[2], judge_Value[3]);
						System.out.println("scene :: game");
					}

				};

				back_Image.setBounds(0, 0, CANVAS_SIZE_X, CANVAS_SIZE_Y);
				play_Game_bt.setBounds(CANVAS_SIZE_X / 2 - 75,
						CANVAS_SIZE_Y / 2 - 150, 0, 0);
				exit_bt.setBounds(CANVAS_SIZE_X / 2 - 75, CANVAS_SIZE_Y / 2, 0,
						0);

				jp.add(back_Image, new Integer(1));

				add(jp);
				start_bt.setBounds(CANVAS_SIZE_X / 2 - 50,
						CANVAS_SIZE_Y / 2 - 50, startbutton_w, startbutton_h);
				throw_bt.setBounds(40, 430, throwbutton_w, throwbutton_h);

				turn2_bt.setBounds(CANVAS_SIZE_X / 2 - 200,
						CANVAS_SIZE_Y / 2 - 200, 0, 0);

				if (throw_push == 1) {
					button_Set();
				}

			} else if ("Start".equals(name)) {
				start_Button(name);
			} else if ("End".equals(name)) {
				end_Button(name);
			} else if ("Throw".equals(name)) {
				throw_Button(name);
			} else if ("Player 1 WIN!!!!!".equals(name)) {
				Win_Button(name);
			} else if ("Player 2 WIN!!!!!".equals(name)) {
				Win_Button(name);
			} else if ("Do".equals(name)) {
				search_value(1);

			} else if ("Gae".equals(name)) {
				search_value(2);

			} else if ("Gul".equals(name)) {
				search_value(3);

			} else if ("Yut".equals(name)) {
				search_value(4);

			} else if ("Mo".equals(name)) {
				search_value(5);

			} else if ("-Do".equals(name)) {
				search_value(-1);

			} else {
				// do nothing.
			}
			player1_Turn(name);
			player2_Turn(name);
		}
	}

	public void judge(int size1, int size2, int size3, int size4) {
		judge_Value[0] = size1;
		judge_Value[1] = size2;
		judge_Value[2] = size3;
		judge_Value[3] = size4;

	}

	public void button_Set() {
		horse_P1_bt.setBounds(660, 380, 40, 40);
		horse_P2_bt.setBounds(660, 430, 40, 40);
		horse_P1_1_bt.setBounds(710, 380, 40, 40);
		horse_P2_1_bt.setBounds(710, 430, 40, 40);
		turn1_bt.setBounds(CANVAS_SIZE_X / 2 - 200, CANVAS_SIZE_Y / 2 - 200, 0,
				0);
		turn2_bt.setBounds(CANVAS_SIZE_X / 2 - 200, CANVAS_SIZE_Y / 2 - 200, 0,
				0);

	}

	public void set_Frame() {
		frame = new Frame("yutProject");
		setSize(CANVAS_SIZE_X, CANVAS_SIZE_Y);
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
	}

	public void addAction_button() {
		play_Game_bt.addActionListener(this);
		start_bt.addActionListener(this);
		exit_bt.addActionListener(this);
		throw_bt.addActionListener(this);
		horse_P1_bt.addActionListener(this);
		horse_P2_bt.addActionListener(this);
		horse_P1_1_bt.addActionListener(this);
		horse_P2_1_bt.addActionListener(this);
		horse_P1_twin.addActionListener(this);
		horse_P2_twin.addActionListener(this);
		turn1_bt.addActionListener(this);
		turn2_bt.addActionListener(this);
		win_P1.addActionListener(this);
		win_P2.addActionListener(this);
		Do.addActionListener(this);
		Gae.addActionListener(this);
		Gul.addActionListener(this);
		Yut.addActionListener(this);
		Mo.addActionListener(this);
		Back_do.addActionListener(this);
	}

	public void button_Add() {

		jp.add(start_bt, new Integer(1));
		jp.add(throw_bt, new Integer(1));
		jp.add(horse_P1_bt, new Integer(1));
		jp.add(horse_P2_bt, new Integer(1));
		jp.add(horse_P1_1_bt, new Integer(1));
		jp.add(horse_P2_1_bt, new Integer(1));
		jp.add(turn1_bt, new Integer(1));
		jp.add(turn2_bt, new Integer(1));

		add(win_P1);
		add(win_P2);
		jp.add(horse_P1_twin, new Integer(1));
		jp.add(horse_P2_twin, new Integer(1));

		k_Button_add();
	}

	public void k_Button_add() {
		add(Do);
		add(Gae);
		add(Gul);
		add(Yut);
		add(Mo);
		add(Back_do);
	}

	public void k_Button_remove(int data) {
		keep_init -= 1;
		if (keep_doing == true) {
			switch (data) {
			case -1:
				Back_do.setBounds(900, 50, 0, 0);
				break;
			case 1:
				Do.setBounds(930, 50, 0, 0);
				break;
			case 2:
				Gae.setBounds(960, 50, 0, 0);
				break;
			case 3:
				Gul.setBounds(990, 50, 0, 0);
				break;
			case 4:
				Yut.setBounds(900, 100, 0, 00);
				break;
			case 5:
				Mo.setBounds(930, 100, 00, 00);
				break;
			}
		}
	}

	public void start_Button(String name) {
		startbutton_h = 0;
		startbutton_w = 0;
		start_bt.setBounds(CANVAS_SIZE_X / 2 - 50, CANVAS_SIZE_Y / 2 - 50,
				startbutton_w, startbutton_h);

		if_Push_Start();
	}

	public void next_turn() {
		try {
			for (int i = 0; i < 200; i++) {
				Thread.sleep(i / 10);
				if (onemore == false) {
					turn2_bt.setBounds(CANVAS_SIZE_X / 2 - 200,
							CANVAS_SIZE_Y / 2 - 200, i * 2, i * 2);
				} else if (onemore == true) {
					turn1_bt.setBounds(CANVAS_SIZE_X / 2 - 200,
							CANVAS_SIZE_Y / 2 - 200, i * 2, i * 2);
				}

			}
		} catch (Exception ex) {

		}
		if (onemore == false) {
			turn2_bt.setBounds(CANVAS_SIZE_X / 2 - 200,
					CANVAS_SIZE_Y / 2 - 200, 0, 0);
		} else if (onemore == true) {
			turn1_bt.setBounds(CANVAS_SIZE_X / 2 - 200,
					CANVAS_SIZE_Y / 2 - 200, 0, 0);
		}
	}

	public void load_Images() {

		scene1 = Toolkit.getDefaultToolkit().getImage("Images/title1.jpg");
		scene2 = Toolkit.getDefaultToolkit().getImage("images/yutpan2.gif");
		yut_img_front = Toolkit.getDefaultToolkit().getImage(
				"images/yut_front.jpg");
		yut_img_back = Toolkit.getDefaultToolkit().getImage(
				"images/yut_back.jpg");
		yut_img_bottom = Toolkit.getDefaultToolkit().getImage(
				"images/yut_bottom.jpg");
		yut_img_minus = Toolkit.getDefaultToolkit().getImage(
				"images/minus_DO.jpg");
	}

	public void play_Game_Button(String name) {
		sceneNum = 2;
		repaint();
		game_Start = 1;
	}

	public void search_value(int value) {

		int i;
		int check = 0;
		for (i = 0; i < 10; i++) {
			if (keep_Array[i] == value) {
				System.out.printf("저장위치 %d , 저장값 : %d\n", i, value);

				main.size = value;
				bt_value = i;
			}
			keep_doing = true;
			onemore = false;
			go = true;

		}
	}

	public void keep_init_bt() {
		if (keep_init == 0) {
			for (int i = 0; i < 10; i++) {
				keep_Array[i] = 0;
			}
			array_count = 0;
		}
	}

	public void keep_value(int size) {
		keep_init += 1;
		
		keep_Array[array_count] = size;
		System.out.printf("%d 번째 저장 값: %d\n", array_count,
				keep_Array[array_count]);

		if (size == 4 || size == 5) {
			if (size == 4) {
				Yut.setBounds(500 + (array_count * 30), 50, 20, 20);
			} else if (size == 5) {
				Mo.setBounds(500 + (array_count * 30), 50, 20, 20);
			}
			array_count++;
			main.keep = true;
		}

		else {
			if (size == 1) {
				Do.setBounds(500 + (array_count * 30), 50, 20, 20);
			} else if (size == 2) {
				Gae.setBounds(500 + (array_count * 30), 50, 20, 20);
			} else if (size == 3) {
				Gul.setBounds(500 + (array_count * 30), 50, 20, 20);
			} else if (size == -1) {
				Back_do.setBounds(500 + (array_count * 30), 50, 20, 20);
			}
			main.keep = false;
			main.more_chance = false;
			throwcount = throwcount - array_count;

		}
	}

	public void if_Push_Start() {
		if (game_Start == 1) {
			game_Start = 2;

			try {

				for (int i = 0; i < 200; i++) {

					turn1_bt.setBounds(CANVAS_SIZE_X / 2 - 200,
							CANVAS_SIZE_Y / 2 - 200, i * 2, i * 2);
					Thread.sleep(i / 10);

				}
			} catch (Exception ep) {

			}
			turn1_bt.setBounds(CANVAS_SIZE_X / 2 - 200,
					CANVAS_SIZE_Y / 2 - 200, 0, 0);
		}
	}

	public void end_Button(String name) {
		System.exit(0);
	}

	public void Win_Button(String name) {
		System.exit(0);
	}

	public void throw_Button(String name) {
		// if (throw_step == true) {
		throw_push = 2;
		repaint();
		go = true;
		throw_step = false;

		if (maindevision == 1)
			main.main(null);

		throwcount++;

		if (main.more_chance == true) {
			onemore = true;
		}
	}

	// }

	public void player1_Turn(String name) {
		if (throwcount % 2 != 0) {
			if (work_together1 == 99) {

				if (name.equals("P1") && go == true) {
					player_process(1);
					next_turn();
					go = false;

					throw_Again();
					// throw_step=true;
				} else if (name.equals("P1-1") && go == true) {

					player_process(2);
					next_turn();
					go = false;

					throw_Again();
					// throw_step=true;
				}
			} else if (work_together1 == 0) {
				if ((name.equals("P1") || name.equals("P1-1")) && go == true) {
					player_process(1);
					player_process(2);
					next_turn();
					go = false;

					// throw_step=true;
					throw_Again();
				}
			}
			keep_init_bt();

		}
	}

	public void player2_Turn(String name) {

		if (throwcount % 2 == 0) {
			if (work_together2 == 99) {

				if (name.equals("P2") && go == true) {

					player_process(3);
					next_turn();
					go = false;

					// throw_step=true;
					throw_Again();

				} else if (name.equals("P2-1") && go == true) {

					player_process(4);
					next_turn();
					go = false;

					throw_Again();
					// throw_step=true;

				}
			} else if (work_together2 == 0) {
				if ((name.equals("P2") || name.equals("P2-1")) && go == true) {
					player_process(3);
					player_process(4);
					next_turn();

					// throw_step=true;
					throw_Again();
				}
			}
keep_init_bt();
		}
	}

	public void throw_Again() {
		if (onemore == true) {
			throwcount--;
			onemore = false;
			main.more_chance = false;
		}
	}

	public void draw_YutImage(Graphics g, int judge1, int judge2, int judge3,
			int judge4) {
		if (main.resultyut != 3) {
			for (int i = 0; i < 4; i++) {
				if (judge_Value[i] == 1) {
					g.drawImage(yut_img_front, 15 + i * 45, 25, 40, 107, this);
				} else if (judge_Value[i] == 0)
					g.drawImage(yut_img_back, 15 + i * 45, 25, 40, 107, this);
			}
		} else {
			if (main.size != -1) {
				for (int i = 0; i < 4; i++) {
					if (judge_Value[i] == 1) {
						g.drawImage(yut_img_front, 15 + i * 45, 25, 40, 107,
								this);
					} else if (judge_Value[i] == 0)
						g.drawImage(yut_img_back, 15 + i * 45, 25, 40, 107,
								this);
				}
			} else if (main.size == -1) {
				for (int i = 0; i < 4; i++) {
					if (judge_Value[i] == 1) {
						g.drawImage(yut_img_front, 15 + i * 45, 25, 40, 107,
								this);
					} else if (judge_Value[i] == 0)
						g.drawImage(yut_img_minus, 15 + i * 45, 25, 40, 107,
								this);
				}
			}

		}
		main.user = 0;
	}

	public void player_process(int part_horse) {

		repaint();

		{
			if (part_horse == 1) {
				substitude_bt = horse_P1_bt;
				turn = 0;
			} else if (part_horse == 2) {
				substitude_bt = horse_P1_1_bt;
				turn = 2;
			} else if (part_horse == 3) {
				substitude_bt = horse_P2_bt;
				turn = 1;
			} else if (part_horse == 4) {
				substitude_bt = horse_P2_1_bt;
				turn = 3;
			}

			maindevision = 2;
			main.main(null);

			if (main.noStart == 0) {
				if (part_horse == 1) {
					substitude_bt.setBounds(660, 380, 40, 40);
				} else if (part_horse == 2) {
					substitude_bt.setBounds(710, 380, 40, 40);
				} else if (part_horse == 3) {
					substitude_bt.setBounds(660, 430, 40, 40);
				} else if (part_horse == 4) {
					substitude_bt.setBounds(710, 430, 40, 40);
				}

				main.noStart = main.trash;
				onemore = false;
				main.total[turn] = 0;
				maindevision = 1;
			} else {
				if (main.inpoint_1[main.turn_main] != 0
						&& main.inpoint_2[main.turn_main] != 0) {

					if (main.total[turn] < 5 && main.total[turn] >= 0) {
						int i = main.total[turn];
						player_x[turn] = CANVAS_SIZE_X / 2 - 25 + (i * 71);
						player_y[turn] = CANVAS_SIZE_Y / 2 + 190 - (i * 48);
						substitude_bt.setBounds(player_x[turn], player_y[turn],
								40, 40);
						if (main.total[turn] == 0) {
							main.total[turn] = 20;
							onemore = false;
						}

					}

					else if (main.total[turn] < 10) {
						int i = main.total[turn] - 5;
						player_x[turn] = CANVAS_SIZE_X / 2 + 330 - (i * 71);
						player_y[turn] = CANVAS_SIZE_Y / 2 - 50 - (i * 48);
						substitude_bt.setBounds(player_x[turn], player_y[turn],
								40, 40);

					} else if (main.total[turn] <= 15) {
						int i = main.total[turn] - 10;
						player_x[turn] = CANVAS_SIZE_X / 2 - 25 - (i * 71);
						player_y[turn] = CANVAS_SIZE_Y / 2 - 290 + (i * 48);
						substitude_bt.setBounds(player_x[turn], player_y[turn],
								40, 40);

					} else if (main.total[turn] <= 20) {
						int i = main.total[turn] - 15;
						player_x[turn] = CANVAS_SIZE_X / 2 - 380 + (i * 71);
						player_y[turn] = CANVAS_SIZE_Y / 2 - 50 + (i * 48);
						substitude_bt.setBounds(player_x[turn], player_y[turn],
								40, 40);

					} else if (main.total[turn] >= 21) {
						substitude_bt.setBounds(700, 100, 40, 40);
						main.main(null);
					}

				}
				/*
				 * -------------구 --분
				 * --선----------------------------------------- -----------
				 */
				else if (main.inpoint_1[main.turn_main] == 0
						&& main.inpoint_1_etc[main.turn_main] != 0) {

					if (main.total[turn] == 4) {
						player_x[turn] = CANVAS_SIZE_X / 2 - 25 + (4 * 71);
						player_y[turn] = CANVAS_SIZE_Y / 2 + 190 - (4 * 48);
						substitude_bt.setBounds(player_x[turn], player_y[turn],
								40, 40);

						main.inpoint_1[main.turn_main] = main.trash;
						onemore = false;
					}

					else if (main.total[turn] <= 11 && main.total[turn] >= 5) {
						int i = main.total[turn] - 5;
						if (i == 3) {
							main.inpoint_3[main.turn_main] = 0;

							player_x[turn] = CANVAS_SIZE_X / 2 + 330
									- (i * 118);
							player_y[turn] = CANVAS_SIZE_Y / 2 - 50;
							substitude_bt.setBounds(player_x[turn],
									player_y[turn], 40, 40);
							main.inpoint_1[main.turn_main] = main.trash;
							use1 = 1;
						} else if (use1 != 1) {

							player_x[turn] = CANVAS_SIZE_X / 2 + 330
									- (i * 118);
							player_y[turn] = CANVAS_SIZE_Y / 2 - 50;
							substitude_bt.setBounds(player_x[turn],
									player_y[turn], 40, 40);

						}
					}
					/*
					 * -------------구--분---선--------------------------------
					 * ---------------
					 */
					if (main.inpoint_3[main.turn_main] == 0) {
						if (main.total[turn] == 7) {
							player_x[turn] = CANVAS_SIZE_X / 2 + 330
									- (2 * 118);
							player_y[turn] = CANVAS_SIZE_Y / 2 - 50;
							substitude_bt.setBounds(player_x[turn],
									player_y[turn], 40, 40);

							main.inpoint_3[main.turn_main] = main.trash;
							main.inpoint_1[main.turn_main] = 0;
							use1 = 0;
							onemore = false;
						}

						int i = main.total[turn] - 8;

						if (i <= 3 && main.total[turn] >= 8) {
							player_x[turn] = CANVAS_SIZE_X / 2 - 25;
							player_y[turn] = CANVAS_SIZE_Y / 2 - 50 + (i * 80);
							substitude_bt.setBounds(player_x[turn],
									player_y[turn], 40, 40);

						} else if (i > 3) {

							int h = main.total[turn] - 11;

							main.total[turn] = 20 + h;
							substitude_bt.setBounds(700, 100, 40, 40);
							main.main(null);
						}
					} else if (main.total[turn] > 11) {

						int i = main.total[turn] - 11;
						player_x[turn] = CANVAS_SIZE_X / 2 - 350 + (i * 65);
						player_y[turn] = CANVAS_SIZE_Y / 2 - 40 + (i * 44);
						substitude_bt.setBounds(player_x[turn], player_y[turn],
								40, 40);

						main.total[turn] = 15 + i;
						main.inpoint_1_etc[main.turn_main] = 0;

					}

				}
				/*
				 * -------------구--분--선--------------------------- -----------
				 */
				else if (main.inpoint_2[main.turn_main] == 0
						&& main.inpoint_2_etc[main.turn_main] != 0) {
					if (main.total[turn] == 9) {
						player_x[turn] = CANVAS_SIZE_X / 2 + 330 - (4 * 71);
						player_y[turn] = CANVAS_SIZE_Y / 2 - 50 - (4 * 48);
						substitude_bt.setBounds(player_x[turn], player_y[turn],
								40, 40);

						main.inpoint_2[main.turn_main] = main.trash;
						onemore = false;
					}

					if (main.total[turn] <= 16 && main.total[turn] >= 10) {

						int i = main.total[turn] - 10;
						player_x[turn] = CANVAS_SIZE_X / 2 - 25;
						player_y[turn] = CANVAS_SIZE_Y / 2 - 290 + (i * 80);
						substitude_bt.setBounds(player_x[turn], player_y[turn],
								40, 40);

					} else if (main.total[turn] > 16
							&& main.inpoint_2[main.turn_main] == 0) {

						int h = main.total[turn] - 16;

						main.total[turn] = 20 + h;
						main.inpoint_2_etc[main.turn_main] = 0;

						substitude_bt.setBounds(700, 100, 40, 40);
						main.main(null);

					}
				}
				/*
				 * -----------구
				 * -----분-----선-----------------------------------------
				 * -----------
				 */

				if (part_horse == 1) {
					if (work_together2 == 99) {
						if ((player_x[0] == player_x[1])
								&& (player_y[0] == player_y[1])) {
							horse_P2_bt.setBounds(660, 430, 40, 40);
							main.total[1] = 0;
							main.inpoint_1[1] = main.trash;
							main.inpoint_2[1] = main.trash;
							main.inpoint_3[1] = main.trash;
							onemore = true;
							work_together2 = 99;
						} else if ((player_x[0] == player_x[3])
								&& (player_y[0] == player_y[3])) {
							horse_P2_1_bt.setBounds(710, 430, 40, 40);
							main.total[3] = 0;
							main.inpoint_1[3] = main.trash;
							main.inpoint_2[3] = main.trash;
							main.inpoint_3[3] = main.trash;
							onemore = true;
							work_together2 = 99;
						}
					} else if (work_together2 == 0) {
						if (((player_x[0] == player_x[1]) && (player_y[0] == player_y[1]))
								|| ((player_x[0] == player_x[3]) && (player_y[0] == player_y[3]))) {
							horse_P2_bt.setBounds(660, 430, 40, 40);
							main.total[1] = 0;
							horse_P2_1_bt.setBounds(710, 430, 40, 40);
							main.total[3] = 0;
							main.inpoint_1[1] = main.trash;
							main.inpoint_2[1] = main.trash;
							main.inpoint_3[1] = main.trash;
							main.inpoint_1[3] = main.trash;
							main.inpoint_2[3] = main.trash;
							main.inpoint_3[3] = main.trash;
							onemore = true;
							work_together2 = 99;
						}
					}

					if ((player_x[0] == player_x[2])
							&& (player_y[0] == player_y[2])) {
						work_together1 = 0;
					}

				} else if (part_horse == 3) {
					if (work_together1 == 99) {
						if ((player_x[1] == player_x[0])
								&& (player_y[1] == player_y[0])) {
							horse_P1_bt.setBounds(660, 380, 40, 40);
							main.total[0] = 0;
							main.inpoint_1[0] = main.trash;
							main.inpoint_2[0] = main.trash;
							main.inpoint_3[0] = main.trash;
							onemore = true;
							work_together1 = 99;
						} else if ((player_x[1] == player_x[2])
								&& (player_y[1] == player_y[2])) {
							horse_P1_1_bt.setBounds(710, 380, 40, 40);
							main.total[2] = 0;
							main.inpoint_1[2] = main.trash;
							main.inpoint_2[2] = main.trash;
							main.inpoint_3[2] = main.trash;
							onemore = true;
							work_together1 = 99;
						}
					} else if (work_together1 == 0) {
						if (((player_x[1] == player_x[0]) && (player_y[1] == player_y[0]))
								|| ((player_x[1] == player_x[2]) && (player_y[1] == player_y[2]))) {
							horse_P1_bt.setBounds(660, 380, 40, 40);
							main.total[0] = 0;
							horse_P1_1_bt.setBounds(710, 380, 40, 40);
							main.total[2] = 0;
							main.inpoint_1[0] = main.trash;
							main.inpoint_2[0] = main.trash;
							main.inpoint_3[0] = main.trash;
							main.inpoint_1[2] = main.trash;
							main.inpoint_2[2] = main.trash;
							main.inpoint_3[2] = main.trash;
							onemore = true;
							work_together1 = 99;
						}
					}
					if ((player_x[1] == player_x[3])
							&& (player_y[1] == player_y[3])) {
						work_together2 = 0;
					}
				} else if (part_horse == 2) {
					if (work_together2 == 99) {
						if ((player_x[2] == player_x[1])
								&& (player_y[2] == player_y[1])) {
							horse_P2_bt.setBounds(660, 430, 40, 40);
							main.total[1] = 0;
							main.inpoint_1[1] = main.trash;
							main.inpoint_2[1] = main.trash;
							main.inpoint_3[1] = main.trash;
							onemore = true;
							work_together2 = 99;
						} else if ((player_x[2] == player_x[3])
								&& (player_y[2] == player_y[3])) {
							horse_P2_1_bt.setBounds(710, 430, 40, 40);
							main.total[3] = 0;
							main.inpoint_1[3] = main.trash;
							main.inpoint_2[3] = main.trash;
							main.inpoint_3[3] = main.trash;
							onemore = true;
							work_together2 = 99;
						}
					} else if (work_together2 == 0) {
						if (((player_x[2] == player_x[1]) && (player_y[2] == player_y[1]))
								|| ((player_x[2] == player_x[3]) && (player_y[2] == player_y[3]))) {
							horse_P2_bt.setBounds(660, 430, 40, 40);
							main.total[1] = 0;
							horse_P2_1_bt.setBounds(710, 430, 40, 40);
							main.total[3] = 0;
							main.inpoint_1[1] = main.trash;
							main.inpoint_2[1] = main.trash;
							main.inpoint_3[1] = main.trash;
							main.inpoint_1[3] = main.trash;
							main.inpoint_2[3] = main.trash;
							main.inpoint_3[3] = main.trash;
							onemore = true;
							work_together2 = 99;
						}
					}
					if ((player_x[2] == player_x[0])
							&& (player_y[2] == player_y[0])) {
						work_together1 = 0;
					}
				} else if (part_horse == 4) {
					if (work_together1 == 99) {
						if ((player_x[3] == player_x[0])
								&& (player_y[3] == player_y[0])) {
							horse_P1_bt.setBounds(660, 380, 40, 40);
							main.total[0] = 0;
							main.inpoint_1[0] = main.trash;
							main.inpoint_2[0] = main.trash;
							main.inpoint_3[0] = main.trash;
							onemore = true;
							work_together1 = 99;
						} else if ((player_x[3] == player_x[2])
								&& (player_y[3] == player_y[2])) {
							horse_P1_1_bt.setBounds(710, 380, 40, 40);
							main.total[2] = 0;
							main.inpoint_1[2] = main.trash;
							main.inpoint_2[2] = main.trash;
							main.inpoint_3[2] = main.trash;
							onemore = true;
							work_together1 = 99;
						}
					} else if (work_together1 == 0) {
						if (((player_x[3] == player_x[0]) && (player_y[3] == player_y[0]))
								|| ((player_x[3] == player_x[2]) && (player_y[3] == player_y[2]))) {
							horse_P1_bt.setBounds(660, 380, 40, 40);
							main.total[0] = 0;
							horse_P1_1_bt.setBounds(710, 380, 40, 40);
							main.total[2] = 0;
							main.inpoint_1[0] = main.trash;
							main.inpoint_2[0] = main.trash;
							main.inpoint_3[0] = main.trash;
							main.inpoint_1[2] = main.trash;
							main.inpoint_2[2] = main.trash;
							main.inpoint_3[2] = main.trash;
							onemore = true;
							work_together1 = 99;
						}
					}
					if ((player_x[3] == player_x[1])
							&& (player_y[3] == player_y[1])) {
						work_together2 = 0;
					}

				}

				maindevision = 1;
			}
		}
	}
}
